﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef ApplicationView_h__
#define ApplicationView_h__

#include <d3d11.h>
#include <wrl/client.h>
#include <dxgi1_2.h>
#include <memory>

#include "IApplicationView.h"
#include "../base/Size.h"
#include "../base/Vector.h"
#include "../utility/Singleton.h"

namespace SkyEngine2d
{

	class IProcessMsg;
	class IDirectRender;
	class Render;

	//! 应用程序的视图 
	class SGE_API ApplicationView
		:public IApplicationView
	{
	public:

		ApplicationView();

		~ApplicationView();

		bool init(IProcessMsg* process_handler, const Size& win_size);

		HWND  getHwnd() { return m_wnd; }

		void calculateFrameStats(float frame_cnt);

		virtual void setCaption(const std::wstring& caption = L"") override;

		virtual const std::wstring& getCaption() override;

		virtual const Size& getWinSize() override;

		virtual void setWinPosition(const Vector2& pos) override;

		virtual const Vector2& getWinPosition() override;

		virtual const Size& getDesktopSize() override;

		virtual const Size& getViewSize()override;

		Render* getRender()const;

		void onResize(HWND hwnd, int w, int h);
	protected:

		bool initWindows();

	private:
		//渲染
		std::unique_ptr<Render> m_render;
		//视口的大小
		Size m_winSize; /*!< 窗口尺寸. */
		Size m_viewSize; /*!< 视图大小. */
		Vector2 m_position; /*!< 窗口的位置. */
		//窗口句柄
		HWND  m_wnd;
		//窗口标题
		std::wstring	m_caption;

		bool m_isInit;  /*!< 是否初始化过. */
		Size m_desktopSize; //桌面的大小

		IProcessMsg* m_msgHandler;

		friend LRESULT CALLBACK mainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
	};

}

#endif // ApplicationView_h__
